package com.modern.devtools.model;

import javafx.beans.property.*;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * Represents a saved command snippet/script in the script library.
 */
public class CommandSnippet {
    
    private final StringProperty id = new SimpleStringProperty();
    private final StringProperty title = new SimpleStringProperty();
    private final StringProperty content = new SimpleStringProperty();
    private final StringProperty description = new SimpleStringProperty();
    private final StringProperty category = new SimpleStringProperty();
    private final ObjectProperty<LocalDateTime> createdAt = new SimpleObjectProperty<>();
    private final ObjectProperty<LocalDateTime> updatedAt = new SimpleObjectProperty<>();
    
    // Constructor
    public CommandSnippet(String id, String title, String content) {
        setId(id);
        setTitle(title);
        setContent(content);
    }
    
    // Getters and Setters
    public String getId() {
        return id.get();
    }
    
    public void setId(String id) {
        this.id.set(id);
    }
    
    public StringProperty idProperty() {
        return id;
    }
    
    public String getTitle() {
        return title.get();
    }
    
    public void setTitle(String title) {
        this.title.set(title);
    }
    
    public StringProperty titleProperty() {
        return title;
    }
    
    public String getContent() {
        return content.get();
    }
    
    public void setContent(String content) {
        this.content.set(content);
    }
    
    public StringProperty contentProperty() {
        return content;
    }
    
    public String getDescription() {
        return description.get();
    }
    
    public void setDescription(String description) {
        this.description.set(description);
    }
    
    public StringProperty descriptionProperty() {
        return description;
    }
    
    public String getCategory() {
        return category.get();
    }
    
    public void setCategory(String category) {
        this.category.set(category);
    }
    
    public StringProperty categoryProperty() {
        return category;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt.get();
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt.set(createdAt);
    }
    
    public ObjectProperty<LocalDateTime> createdAtProperty() {
        return createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt.get();
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt.set(updatedAt);
    }
    
    public ObjectProperty<LocalDateTime> updatedAtProperty() {
        return updatedAt;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CommandSnippet that = (CommandSnippet) o;
        return Objects.equals(id.get(), that.id.get());
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(id.get());
    }
    
    @Override
    public String toString() {
        return "CommandSnippet{" +
                "id='" + id.get() + '\'' +
                ", title='" + title.get() + '\'' +
                ", category='" + category.get() + '\'' +
                '}';
    }
}